//
//  swift
//  SinaWeibo
//
//  Created by paycloud110 on 16/6/2.
//  Copyright © 2016年 paycloud110. All rights reserved.
//

import UIKit

class TitleButton: UIButton {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        /** 取消点击时的高亮 */
        adjustsImageWhenHighlighted = false
        setTitle("碧空海", forState: .Normal)
        setTitleColor(UIColor.blackColor(), forState: .Normal)
        setImage(UIImage(named: "navigationbar_arrow_up"), forState: .Normal)
        setImage(UIImage(named: "navigationbar_arrow_down"), forState: .Selected)
        sizeToFit()
        
    }
    required init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented")
        super.init(coder: aDecoder)
    }
    
    /** 交换button内部image和title的位置 一种方法 */
//    override func imageRectForContentRect(contentRect: CGRect) -> CGRect {
//        
//    }
//    override func titleRectForContentRect(contentRect: CGRect) -> CGRect {
//        
//    }
    
    /** 二种方法 回来两次 */
    override func layoutSubviews() {
        super.layoutSubviews()
        
        /** 不靠谱 */
//        titleLabel?.frame.offsetInPlace(dx: -(imageView?.frame.width)!, dy: 0)
//        imageView?.frame.offsetInPlace(dx: (titleLabel?.frame.width)!, dy: 0)
        
        titleLabel?.frame.origin.x = 0
        imageView?.frame.origin.x = (titleLabel?.frame.size.width)! + 5
    }
}
